package design.pattern.Strategy.main;

import design.pattern.Strategy.context.StrategyFactory;
import design.pattern.Strategy.enumeration.ResponseStateEnum;
import design.pattern.Strategy.handle.StrategyHandle;
import design.pattern.Strategy.handle.impl.ErrorCallbackStrategy;
import design.pattern.Strategy.handle.impl.SuccessCallbackStrategy;
import design.pattern.Strategy.handle.impl.WarningCallbackStrategy;

public class MainTest {
  public static void main(String[] args) {
    // 注册策略
    StrategyFactory.register(ResponseStateEnum.WARN, new WarningCallbackStrategy());
    StrategyFactory.register(ResponseStateEnum.ERROR, new ErrorCallbackStrategy());
    StrategyFactory.register(ResponseStateEnum.SUCCESS, new SuccessCallbackStrategy());
    
    // 拿到随机的code
    ResponseStateEnum randomState = ResponseStateEnum.ERROR;
    StrategyHandle strategyHandle = StrategyFactory.get(randomState);
    // 执行策略
    if (strategyHandle != null)
      strategyHandle.handle();
  }
}
